﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Carmenta.SpatialAce.Interop.SpatialAce;

namespace CEPowerPack
{
    public static partial class Factory
    {
        private static Dictionary<string, NameSpace> nsCache = new Dictionary<string, NameSpace>();

        public static NameSpace GetNameSpace(string name)
        {
            if (!nsCache.ContainsKey(name))
            {
                NameSpace ns = new NameSpace();
                ns.Name = name;
                nsCache[name] = ns;
            }

            return nsCache[name];
        }

        public static RefSystem GetRefSystem(string name)
        {
            int dotPos = name.IndexOf('.');
            string nsName;
            string rsName;
            if (dotPos >= 0)
            {
                nsName = name.Substring(0, dotPos);
                rsName = name.Substring(dotPos + 1);
            }
            else
            {
                nsName = "World";
                rsName = name;
            }

            return GetNameSpace(nsName).RefSystem[rsName];
        }

        public static AttributeVariable CreateDirectAttributeVariable<T>(T value)
        {
            var result = new AttributeVariable();
            result.Value = value;
            return result;
        }

        public static AttributeVariable CreateDirectColorAttributeVariable(short r, short g, short b, short a = 255)
        {
            var result = new AttributeVariable();
            result.Value = new SpaceRGB() { R = r, G = g, B = b, A = a };
            return result;
        }
    }
}
